package com.cskaoyan.gateway.controller.shopping;

import com.cskaoyan.gateway.util.ShoppingGoodsUtil;
import com.mall.commons.result.GoodsResponseData;
import com.mall.commons.result.GoodsResponseUtil;
import com.mall.shopping.ShoppingGoodsService;
import com.mall.shopping.ShoppingRecommendService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.GoodsRequest;
import com.mall.shopping.dto.GoodsResponse;
import com.mall.shopping.dto.RecommendResponse;
import com.mall.shopping.model.ShoppingGoodsBo;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @description: TODO
 * @author: jiaolei
 * @date: 2021/12/12 17:51
 */
@RestController
@RequestMapping("shopping")
public class GoodsController {

    //调用api里的接口
    @Reference(timeout = 7000,retries = 0,check = false)
    ShoppingGoodsService shoppingGoodsService;

    @Reference(timeout = 7000,retries = 0,check = false)
    ShoppingRecommendService shoppingRecommendService;

    @GetMapping("goods")
    @Anoymous
    public GoodsResponseData goods(ShoppingGoodsBo shoppingGoodsBo){
        //把bo作为request的变量，并定义check方法校验参数的合法性
        GoodsRequest goodsRequest = new GoodsRequest();
        goodsRequest.setShoppingGoodsBo(shoppingGoodsBo);
        //在接口的实现里check
        //调用服务
        GoodsResponse goodsResponse= shoppingGoodsService.goods(goodsRequest);
        //把vo作为response的变量，定义response
        return ShoppingGoodsUtil.getGoodsResponseData(goodsResponse,goodsResponse.getShoppingGoodsVo());
    }

    @GetMapping("recommend")
    @Anoymous
    public GoodsResponseData recommend(){
        //调用服务
        //定义自己的response进行处理
        RecommendResponse recommendResponse=shoppingRecommendService.recommend();

        return ShoppingGoodsUtil.getGoodsResponseData(recommendResponse,recommendResponse.getPanelContentItemDtos());
    }
}
